package com.learncloud.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.learncloud.common.core.wrapper.ResponseWrap;
import com.learncloud.common.core.wrapper.ResponseWrapUtil;
import com.learncloud.entity.VideoResource;
import com.learncloud.service.IVideoResourceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 视频资源资源表 前端控制器
 * </p>
 *
 * @author yj
 */
@RestController
@RequestMapping("/video/resource")
public class VideoResourceController {

    @Autowired
    private IVideoResourceService iVideoResourceService;

    @PostMapping("/add")
    @ApiOperation(value = "新增视频资源")
    public ResponseWrap<VideoResource> add(@RequestBody VideoResource videoResource){
        boolean save = iVideoResourceService.save(videoResource);
        return ResponseWrapUtil.success(videoResource);
    }

    @PostMapping("/addTx")
    @ApiOperation(value = "新增视频资源")
    public ResponseWrap<VideoResource> addTx(@RequestBody List<VideoResource> videoResources){
        boolean save = iVideoResourceService.addTx(videoResources);
        return ResponseWrapUtil.success();
    }


    @PostMapping ("/update")
    @ApiOperation(value = "修改视频资源")
    public ResponseWrap<VideoResource> update(@RequestBody VideoResource videoResource){
        boolean update = iVideoResourceService.updateById(videoResource);
        return ResponseWrapUtil.success();
    }

    @DeleteMapping("/del")
    @ApiOperation(value = "删除视频资源")
    public ResponseWrap del(Integer id){

        boolean b = iVideoResourceService.del(id);
        return ResponseWrapUtil.success();
    }

    @GetMapping("/getSucList")
    @ApiOperation(value = "通过id 获取已转码成功的资源信息")
    public ResponseWrap getList(Integer videoDraId){
        List<VideoResource> list = iVideoResourceService.list(new QueryWrapper<>(new VideoResource().setVideoDraId(videoDraId).setStatus("2")));
        return ResponseWrapUtil.success(list);
    }

    @GetMapping("/getPaginationList")
    @ApiOperation(value = "查询视频资源列表")
    public ResponseWrap<Page> getPaginationList(Integer pageSize, Integer pageIndex, VideoResource videoResource){
        Page page = iVideoResourceService.page(new Page(pageIndex, pageSize),new QueryWrapper<>(videoResource));
        return ResponseWrapUtil.success(page);
    }

    @GetMapping("/transcode")
    @ApiOperation(value = "除视频资源转m3u8")
    public ResponseWrap transcode(Integer id){
        iVideoResourceService.transcode(id);
        return ResponseWrapUtil.success();
    }

}

